<?php
require_once($_SERVER['DOCUMENT_ROOT']."/jeng/jeng.php");

ptaste();

class LoginUser extends JEngService
{
	function renderXml()
	{
	  $uname=$this->common_db()->unhack($this->utils()->commonHelper()->gpVar("user"));
	  $upass=$this->common_db()->unhack($this->utils()->commonHelper()->gpVar("password"));
	  //$this->logger()->debug("LOGUSR nm=%s ps=%s",$uname,$upass);
	  $nm=$uname;
	  $res=$this->common_db()->queryf("SELECT id,name,fullname,parent,
		CONCAT(rights,(SELECT rights FROM users WHERE id= urs.parent)) as rights,
		email,
		(SELECT name FROM users WHERE id=urs.parent) as `group` 
		FROM users urs WHERE (email='%s') AND password=MD5('%s');",$nm,$upass);
	  $xml=$this->emptyXML("login_user_result");
	  $qr=1;
	  if ($res)
	    if ($res->rows()==1)
		{
			$uxml=JEngDBXml::s_render($res);
			JEngXCombiner::s_render($xml,$uxml,"login_user_result","row",JEngXCombiner::HOW_APPEND | JEngXCombiner::HOW_ONCE);
			$qr=0;
		}
	  $rattr=$xml->createAttribute("result");
	  $rattr->appendChild($xml->createTextNode(sprintf("%d",$qr)));
	  $xml->documentElement->appendChild($rattr);
	  return $xml;
	}
}

$obj=new LoginUser();
echo $obj->render();

?>